<?php
/**
 * Created by PhpStorm.
 * User: CYJiao
 * Date: 6/6/15
 * Time: 16:44
 */

?>

<script>
    $(function(){
        $(window).resize(function(){
            $('#datagrid').datagrid('resize', {
                width:function(){
                    return document.body.clientWidth;
                },
                height:function(){
                    return document.body.clientHeight;
                }
            });
        });

        $('#datagrid').datagrid({
            url: "<?php echo CController::createUrl('medicine/Getwestern_'); ?>",
            pagination: true,
            pageSize: 20,
            fit: true,
            striped: true,
            remoteSort:false,
            fitColumns: true,
            nowrap: false,
            border: false,
            singleSelect:true,
            rownumbers:true,//行号
            frozenColumns:[[
                
                {field:'medicine_name',title:'药品名称',sortable:true,width:100}
            ]],
            idField: 'id', // 跨页选择使用
            columns:
                [[
                   {
                        title:'药品分类',
                        field:'category',
                        width:100
                    },{
                        title:'药品规格',
                        field:'specification',
                        width:100
                    },
                    //{
                    //     title:'保质期',
                    //     field:'expiry_date',
                    //     width:100
                    // },{
                    //     title:'包装',
                    //     field:'unit',
                    //     width:100
                    // },
                    {
                        title:'价格',
                        field:'price',
                        width:100
                    }
                ]],
            onClickRow:function(rowIndex,rowData){
                var check = $('#datagrid').datagrid('getSelected');
                var rows = rowData;
                if(check != null){
                    
                    var html = '<tr class="prescription_medicine">';
                    if($("#hidden_id_"+rows._id.$id).val() != rows._id.$id){
                        if(rows != ''){
                            html += '<td style="width:100px" class="medicine_name"><input style="width:100px" name="medicine_name" value="'+rows.medicine_name+'"></td><td style="width:80px"><input style="width:80px" name="yongliang"></td><td><select name="yongfa" style="width:70px;"><option value="42">口服</option><option value="2">静脉注射</option><option value="1">外用</option><option value="8">冲服</option><option value="9">煎服</option></select></td><td style="width:100px"><input style="width:100px" name="beizhu"/></td><td style="width:60px"><select name="pindu"><option value="1">一天一次</option><option value="2">一天两次</option><option value="3">一天三次</option><option value="4">一天四次</option><option value="5">2小时一次</option><option value="6">4小时一次</option><option value="7">6小时一次</option><option value="8">8小时一次</option><option value="12">睡前一次</option></select></td><td style="width:20px"><input style="width:30px" name="day"></td><td style="width:20px"><input style="width:30px" name="count"></td><td style="width:30px" class="price"><input style="width:30px" name="price" value="'+rows.price+'"></td><td><a href="#" onclick="remove_medicine(this);" class="easyui-linkbutton" data-options="iconCls:icon-remove">删除</a></td><td><input type="hidden" id="hidden_id_'+rows._id.$id+'" value="'+rows._id.$id+'"><td>';
                            html += '</tr>';
                            $("#pre_medicine").append(html);
                           
                        }
                    }
                    
                }else{
                    $("#hidden_id_"+rows._id.$id).parent("td").parent("tr").remove();

                }
                
                
            },
            toolbar: '#toolbar'
        });
 
    });

    $('#add_medicine').click(function(){
        $('#datagrid_search').datagrid({
        url: "<?php echo CController::createUrl('medicine/Searchall'); ?>",
        fit: true,
        height: 'auto',
        striped: true,
        remoteSort:false,
        fitColumns: false, 
        nowrap: false,
        border: false,
        singleSelect:false,
        rownumbers:true,//行号
        columns:
            [[
                {
                    field:'product_name_ch',
                    title:'产品中文名称'
                },
                {
                    title:'产品英文名称',
                    field:'product_name_en',
                    width:100
                },{
                    title:'规格',
                    field:'specification',
                    width:100
                },{
                    title:'药效',
                    field:'efficacy',
                    width:100
                },{
                    title:'药理',
                    field:'pharmaco',
                    width:100
                },{
                    title:'副作用',
                    field:'side_effect',
                    width:100
                }
            ]],
           
        })
        $('#dlg_medicine_add').window('open');
    })

    $('#medicine_name').searchbox({  
        searcher : function(value,name){
             $('#datagrid').datagrid('load',{
            medicine_name : $('#medicine_name').val(),
            //url: "<?php echo CController::createUrl('medicine/Getwestern_'); ?>"
            })
        }
    });
    
    $('.searchbox-button').on('click',function(){
       
    })
    $('.search_all').on('click',function(){
        $('#datagrid_search').datagrid('load',{
            product_name_ch : $('.product_name_ch').val(),
            url: "<?php echo CController::createUrl('medicine/Searchall'); ?>"
        })
    })
    $('#reflush_medicine').click(function(){
        $('#datagrid').datagrid('load',{url: "<?php echo CController::createUrl('medicine/Getwestern_'); ?>"})
    })
    $('.add_my_medicine').on('click',function(){
        $('#dlg_medicine_add').window('close')
        $('#main-tab').tabs('add',{
            title:'添加药品',
            content:'<iframe scrolling="auto" frameborder="0"  src="<?php  echo CController::createUrl("medicine/addmedicine"); ?>" style="width:100%;height:100%;"></iframe>',
            closable:true
        });
    });
    $('#manage_medicine').on('click',function(){
        $('#main-tab').tabs('add',{
            title:'管理药品',
            content:'<iframe scrolling="auto" frameborder="0"  src="<?php  echo CController::createUrl("medicine/manage"); ?>" style="width:100%;height:100%;"></iframe>',
            closable:true
        });
    });
    function remove_medicine(medicine){
        
        $(medicine).parent("td").parent("tr").remove();
    }


</script>



<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',fit:true,border:false" style="overflow: hidden;">
        <table id="datagrid" data-options="border:false,fit:true" style="height: 500px;">
        </table>
        <div id="toolbar">
            <table style="border-spacing:0">
                <tr>
                    <td>
                        <input id="medicine_name" style="width:110px" />
                    </td>
                   
                    <!--<td>
                        <a href="#" id="add_medicine" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
                    </td>-->
                    <td>
                        <a href="#" id="reflush_medicine" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="">刷新列表</a>
                    </td>
                    <td>
                        <a href="#" id="manage_medicine" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="">管理药品</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div id="dlg_medicine_add" class="easyui-window" title="添加药品" closed="true" style="width:600px;height:300px;padding:5px;">
    <table style="border-spacing:0">
        <tr>
            <td>
                <input class="easyui-searchbox product_name_ch"  style="width:150px" />
            </td>
            <td>
                <a href="#" class="easyui-linkbutton search_all" data-options="iconCls:'icon-search'">总库查找</a>
            </td>
            <td>
                <a href="#" class="easyui-linkbutton add_my_medicine" data-options="iconCls:'icon-add'">手动添加</a>
            </td>
        </tr>
    </table>
    <table id="datagrid_search" data-options="border:false,fit:true" style="height: 500px;">  
    </table>
</div>
</div>


